/*
 * Image.cpp
 *
 *  Created on: 03.09.2012
 *      Author: caffeine
 */

#include "Image.h"
#include <log/Log.h>

namespace irr{
namespace gui{

Image::Image(irr::video::ITexture*t) {
	texture=t;
	if (texture)
		texture->grab();
}

Image::~Image() {
	texture->drop();
}

void Image::render(irr::video::IVideoDriver*driver,irr::core::recti rect){
	driver->draw2DImage(texture,rect,irr::core::recti(irr::core::vector2di(0,0),texture->getSize()),0,0,true);
}

Image*Image::createImage(irr::video::IVideoDriver*driver,irr::io::path fileName){
	irr::video::ITexture*t=driver->getTexture(fileName);
	if (t)
		return new Image(t);
	LOGE("Can't find texture \"%s\"",fileName.c_str());
	exit(0);
	return 0;
}

irr::u32 Image::getMargin(MarginSide type){
	return 0;
}

Image*Image::createImage(irr::video::IVideoDriver*driver,irr::io::IReadFile*file){
	irr::video::ITexture*t=driver->getTexture(file);
	if (t)
		return new Image(t);
	return 0;
}



}//namespace gui
}//namespace irr
